import request from "@/utils/request";

/**
 * 加入购物车
 * @param {number} skuId 商品id
 * @param {number} skuNum 商品数量
 * @returns
 */
export const reqAddToCart = (skuId, skuNum) => {
  return request({
    method: "POST",
    url: `/cart/addToCart/${skuId}/${skuNum}`,
  });
};

/**
 * 获取购物车列表
 * @returns 购物车列表
 */
export const reqGetCartList = () => {
  return request({
    method: "GET",
    url: `/cart/cartList`,
  });
};

/**
 * 更新商品选中状态
 * @param {number} skuId 商品id
 * @param {number} isChecked 选中状态
 * @returns
 */
export const reqUpdateCartIsChecked = (skuId, isChecked) => {
  return request({
    method: "GET",
    url: `/cart/checkCart/${skuId}/${isChecked}`,
  });
};

/**
 * 删除商品
 * @param {number} skuId 商品id
 * @returns
 */
export const reqDelCart = (skuId) => {
  return request({
    method: "DELETE",
    url: `/cart/deleteCart/${skuId}`,
  });
};

/**
 * 批量删除商品
 * @param {Array} skuIdList 商品id列表
 * @returns
 */
export const reqBatchDelCart = (skuIdList) => {
  return request({
    method: "POST",
    url: `/cart/batchDeleteCart`,
    data: skuIdList,
  });
};

/**
 * 批量修改商品的状态
 * @param {*} skuIdList
 * @param {*} isChecked
 * @returns
 */
export const reqBatchCheckCart = (skuIdList, isChecked) => {
  return request({
    method: "POST",
    url: `/cart/batchCheckCart/${isChecked}`,
    data: skuIdList,
  });
};
